package com.smooth.site.sx.pc.student.service;

import java.util.List;
import java.util.Objects;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.smooth.common.site.common.enums.SiteCodeEnums;
import com.smooth.common.site.common.excep.SiteException;
import com.smooth.common.site.modules.sys.service.SystemService;
import com.smooth.dao.gen.BizStudentMapper;
import com.smooth.dao.gen.bean.BizStudent;
import com.smooth.dao.gen.bean.BizStudentExample;
import com.smooth.site.sx.mag.biz.student.service.BizStudentService;
import com.smooth.site.sx.pc.student.req.StudenRegVo;
import com.smooth.sys.site.biz.sms.bx.service.SmsCodeService;

@Service
public class PcStudentService {
	@Autowired
	BizStudentService bizStudentService;
	@Autowired
	SmsCodeService smsCodeService;
	@Autowired
	BizStudentMapper bizStudentMapper;
	public BizStudent registerStudent(StudenRegVo studenRegVo) {
		if(smsCodeService.verfyCode(studenRegVo.getTelNo(), studenRegVo.getVerCode())) {
			BizStudent bizStudent = new BizStudent();
			bizStudent.setTelNo(studenRegVo.getTelNo());
			
			if(StringUtils.isNotBlank(studenRegVo.getPassword())) {
				String enPassword = SystemService.entryptPassword(studenRegVo.getPassword());
				bizStudent.setPassword(enPassword);
			}
			bizStudentService.save(bizStudent);
			return bizStudent;
		}else {
			throw new SiteException(SiteCodeEnums.param_error,"短信验证码错误，请重新获取");
		}
	}
	
	public BizStudent queryById(String id) {
		return bizStudentService.get(id);
	}
	
	
	public static double getRateComplete(BizStudent bizStudent) {
		if(bizStudent==null) {
			return 0d;
		}
		double sumnum = 21.00d;
		
		double compNum = 0.0d;
		if(StringUtils.isNotBlank(bizStudent.getStuName())) {
			compNum = compNum + 1;
		}
		
		if(bizStudent.getGender()!=null) {
			compNum = compNum + 1;
		}
		
		
		if(bizStudent.getBirthday()!=null) {
			compNum = compNum + 1;
		}
		
		
		if(bizStudent.getStuHeight()!=null && bizStudent.getStuHeight()>0) {
			compNum = compNum + 1;
		}
		
		
		if(bizStudent.getStuWeight()!=null && bizStudent.getStuWeight()>0) {
			compNum = compNum + 1;
		}
		
		
		if(bizStudent.getJobStatus()!=null) {
			compNum = compNum + 1;
		}
		
		
		if(StringUtils.isNotBlank(bizStudent.getTelNo())) {
			compNum = compNum + 1;
		}
		
		if(StringUtils.isNotBlank(bizStudent.getStuNation())) {
			compNum = compNum + 1;
		}
		
		if(StringUtils.isNotBlank(bizStudent.getNativePalce())) {
			compNum = compNum + 1;
		}
		
		if(StringUtils.isNotBlank(bizStudent.getCityId())) {
			compNum = compNum + 1;
		}
		
		if(StringUtils.isNotBlank(bizStudent.getProvinceId())) {
			compNum = compNum + 1;
		}
		
		if(StringUtils.isNotBlank(bizStudent.getDomicile())) {
			compNum = compNum + 1;
		}
		
		if(StringUtils.isNotBlank(bizStudent.getCollegeLevel())) {
			compNum = compNum + 1;
		}
		
		if(StringUtils.isNotBlank(bizStudent.getSchId())) {
			compNum = compNum + 1;
		}
		
		if(StringUtils.isNotBlank(bizStudent.getSubjectId())) {
			compNum = compNum + 1;
		}
		
		if(StringUtils.isNotBlank(bizStudent.getHighSchName())) {
			compNum = compNum + 1;
		}
		
		if(StringUtils.isNotBlank(bizStudent.getMidSchName())) {
			compNum = compNum + 1;
		}
		
		
		if(StringUtils.isNotBlank(bizStudent.getPicBody())) {
			compNum = compNum + 1;
		}
		if(StringUtils.isNotBlank(bizStudent.getPicHead())) {
			compNum = compNum + 1;
		}
		if(StringUtils.isNotBlank(bizStudent.getPicLife())) {
			compNum = compNum + 1;
		}
		if(StringUtils.isNotBlank(bizStudent.getPicNomake())) {
			compNum = compNum + 1;
		}
		
		return compNum/sumnum;
	}
	public BizStudent updStudent(BizStudent bizStudent) {
		bizStudent.setDelFlag(null);
		bizStudentService.save(bizStudent);
		return queryById(bizStudent.getId());
	}
	public BizStudent queryByTelNo(String telNo) {
		BizStudentExample bizStudentExample = new BizStudentExample();
		BizStudentExample.Criteria criteria = bizStudentExample.createCriteria();
		
		criteria.andTelNoEqualTo(telNo);
		
		List<BizStudent>  blist = bizStudentMapper.selectByExample(bizStudentExample);
		if(blist.size()>0) {
			return blist.get(0);
		}
		return null;
	}
}
